﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SysChangeLog
    {
    	#region public properties
		[Required(ErrorMessage="ChangeLogID Required")]
		public int ChangeLogID { get; set; }
		[Required(ErrorMessage="UserID Required")]
		public int UserID { get; set; }
		[Required(ErrorMessage="Table Name Required")]
		public string TableName { get; set; }
		[Required(ErrorMessage="DataID Required")]
		public int DataID { get; set; }
		public DateTime? ActionDate { get; set; }
		public int? Status { get; set; }
		#endregion

		#region constructor
		public SysChangeLog(){ }

		public SysChangeLog(IDataReader rd)
		{
			this.ChangeLogID = (int)rd["ChangeLogID"];
			this.UserID = (int)rd["UserID"];
			this.TableName = rd["TableName"].ToString();
			this.DataID = (int)rd["DataID"];
			this.ActionDate = rd["ActionDate"].Equals(DBNull.Value) ? (DateTime?)null : (DateTime)rd["ActionDate"];
			this.Status = rd["Status"].Equals(DBNull.Value) ? (int?)null : (int)rd["Status"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSysChangeLog.Create(UserID, TableName, DataID, ActionDate, Status);
        }

        private bool Update()
        {
            return DBSysChangeLog.Update(ChangeLogID, UserID, TableName, DataID, ActionDate, Status);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(ChangeLogID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int ChangeLogID)
        {
            return DBSysChangeLog.Delete(ChangeLogID);
        }

        public static List<SysChangeLog> GetAll()
        {
            return ObjectClass.CreateList<SysChangeLog>(DBSysChangeLog.GetAll());
        }

        public static SysChangeLog GetByKey(int ChangeLogID)
        {
            return ObjectClass.CreateInstance<SysChangeLog>(DBSysChangeLog.GetByKey(ChangeLogID));
        }

        public static List<SysChangeLog> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SysChangeLog>(DBSysChangeLog.GetByTop(top, where, order));
        }
		#endregion
	}
}
